﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - HRWorkload" 
*/ 

component 
	displayname="public.service.db.senate.sequence.HRWorkload" 
	output=false 
	accessors=true 
	{

	
	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "自定义主键规则"
	*/
	public string function getID() output=false {
		
		var nextID = "B" & numberFormat(1, "0_");
	
		var sql = "SELECT a.hrt 
					FROM t_hr_workload a  
					WHERE a.hrt LIKE :condition 
					ORDER BY a.hrt DESC";

		var queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		queryObj.addParam( name="condition", value="B" & "__" , cfsqltype="cf_sql_char" );
		var rs_check = queryObj.execute(sql = sql).getResult();

		/* 
			主键生成规则 CHAR(3)
			
			B + 2位流水号
		*/
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = "B" & numberFormat((right(rs_check["hrt"][1], 2) + 1), "0_");
			
		}
		
		return nextID;
	}

}

</cfscript>